import { getProListData } from './../pages/services/pro'
import { Effect, Reducer } from 'umi'
import { IPro } from '@/pages/pro/pro'
// 构建产品管理的dva数据流
export interface IProState {
    proList: IPro[]
    recommendList: IPro[]
    seckillList: IPro[]
    searchList: IPro[]
}

export interface IProModel {
    namespace: 'pro',
    state:IProState,
    effects: {
        getProListAction: Effect
    },
    reducers: {
        changeProList: Reducer,
        changeRecommendList: Reducer,
        changeSeckillList: Reducer,
        changeSearchList: Reducer,
    }
}

const userModel: IProModel = {
    namespace: 'pro',
    state: {
        proList: [],
        recommendList: [],
        seckillList: [],
        searchList: []
      },
    effects: {
        *getProListAction({payload}: any, { call, put }: any) {
            const res = yield call(getProListData, payload)
            yield put({
                type: 'changeProList',
                payload: res.data.data
            })
        }
    },
    reducers: {
        changeProList(state: any, action: any) {
            state.proList = action.payload
        },
        changeRecommendList(state: any, action: any) {
            state.recommendList = action.payload
        },
        changeSeckillList(state: any, action: any) {
            state.seckillList = action.payload
        },
        changeSearchList(state: any, action: any) {
            state.searchList = action.payload
        }
    }

}

export default userModel